/*
 * exame_2010_11_junho_Q1.c
 *
 *  Created on: Jun 18, 2012
 *      Author: ubuntu
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int somait(int a, int b) {
	if (b < a) {
		return -1;
	}

	int somatorio = 0;
	int aAux = a;
	while (aAux <= b) {
		if (aAux % 3 == 0 && aAux % 2 > 0) {
			somatorio += aAux;
		}
		aAux++;
	}
	return somatorio;
}

int somarec(int a, int b) {
	if (b < a) {
		return -1;
	}

	int somatorio = 0;
	if (a % 3 == 0 && a % 2 > 0) {
		somatorio = a;

	}
	if (a < b) {
		return somatorio + somarec(++a, b);
	}

	return somatorio;

}

int main(int argc, char **argv) {
	if (argc < 3) {
		fprintf(stderr, "Usage %s <a> <b>\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	int a = atoi(argv[1]);
	int b = atoi(argv[2]);
	printf("somait %d %d -> %d\n", a, b, somait(a, b));
	printf("somarec %d %d -> %d\n", a, b, somarec(a, b));
}
